package com.zzh.utils;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 张占恒.
 * @date 2020/8/27.
 * @time 16:25.
 */
@Component
public class RabbitmqMessageSend {
    @Autowired
    RabbitTemplate rabbitTemolate;

    public void sendMessage(String message,String rouingKey,String name){
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId("订单ID");
        Map<String,Object> map = new HashMap<>();
        map.put("name","123");
        map.put("password","123456");
        rabbitTemolate.convertAndSend("testQueue","direct.key", JSON.toJSONString(map),correlationData);
    }

}
